package utils

import (
	"bytes"
	"golang.org/x/text/encoding/simplifiedchinese"
	"golang.org/x/text/transform"
	"io/ioutil"
	"regexp"
)

func UTF82GB2312(s []byte) ([]byte, error) {
	reader := transform.NewReader(bytes.NewReader(s), simplifiedchinese.GB18030.NewEncoder())
	d, e := ioutil.ReadAll(reader)
	if e != nil {
		return nil, e
	}
	return d, nil
}

func CheckMobile(mobile string) bool {
	reg := `^1([3456789])\d{9}$`
	rgx := regexp.MustCompile(reg)
	return rgx.MatchString(mobile)
}

func CheckYnMobile(mobile string) bool {
	reg := `\d{9,10}$`
	rgx := regexp.MustCompile(reg)
	return rgx.MatchString(mobile)
}
